
from copy import copy

def pandigital_iter(numbers):
    if len(numbers) == 1:
        yield str(numbers[0])
    else:
        for i in numbers:
            remain_numbers = copy(numbers)
            remain_numbers.remove(i)
            for j in pandigital_iter(remain_numbers):
                yield str(i) + j

sum = 0
for sp in pandigital_iter(range(9, -1, -1)):
    p = int(sp)
    #      9876543210
    if p < 1000000000:
        break
    sp = str(p)
    if int(sp[1:4]) % 2 == 0 \
        and int(sp[2:5]) % 3 == 0 \
        and int(sp[3:6]) % 5 == 0 \
        and int(sp[4:7]) % 7 == 0 \
        and int(sp[5:8]) % 11 == 0 \
        and int(sp[6:9]) % 13 == 0 \
        and int(sp[7:]) % 17 == 0:
        print p
        sum += p
print 'sum:', sum
    